package yur.wedding.modules.sys.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import yur.wedding.common.utils.Query;

import yur.wedding.modules.sys.dao.SysDocdetailLogDao;
import yur.wedding.modules.sys.entity.SysDocdetailLogEntity;
import yur.wedding.modules.sys.entity.SysDocshareEntity;
import yur.wedding.modules.sys.entity.SysUserEntity;
import yur.wedding.modules.sys.service.SysDocdetailLogService;
import yur.wedding.modules.sys.service.SysUserService;
import yur.wedding.utils.PageUtils;

import javax.annotation.Resource;


@Service("sysDocdetailLogService")
public class SysDocdetailLogServiceImpl extends ServiceImpl<SysDocdetailLogDao, SysDocdetailLogEntity> implements SysDocdetailLogService {
    @Resource
    SysUserService user;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysDocdetailLogEntity> page = this.page(
                new Query<SysDocdetailLogEntity>().getPage(params),
                new QueryWrapper<SysDocdetailLogEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 单个文档查询 日志信息
     * @return
     */
    @Override
    public List<SysDocdetailLogEntity> getLogList(Long dbgyId) {

        List<SysDocdetailLogEntity> docid = baseMapper.selectList(new QueryWrapper<SysDocdetailLogEntity>().eq("docid", dbgyId));
        return docid;
    }


    /**
     * 获取单个文档有那些日志
     */
    @Override
    public PageUtils getlogList(Long dbgyId, Map<String, Object> params) {

        IPage<SysDocdetailLogEntity> page = this.page(
                new Query<SysDocdetailLogEntity>().getPage(params),
                new QueryWrapper<SysDocdetailLogEntity>().eq(true, "docid", dbgyId)
        );
        for (SysDocdetailLogEntity entity : page.getRecords()) {
            if (entity.getOperateuserid()!=null){
                SysUserEntity byId = user.getById(entity.getOperateuserid());
                entity.setName(byId.getLastName());
            }


        }

        return new PageUtils(page);
    }

    /**
     * 查询当前操作人是否存在操作日志
     * @param dbgyId
     * @param userId
     * @param i
     * @return
     */
    @Override
    public SysDocdetailLogEntity userInfolog(Long dbgyId, Long userId, int i) {

        return baseMapper.selectOne(new QueryWrapper<SysDocdetailLogEntity>()
                .eq(true, "docid", dbgyId).eq("operateuserid",userId).eq("operatetype",i));
    }

}
